package authoritah.ui.spend;

import java.util.ArrayList;

import javax.swing.table.DefaultTableModel;

import authoritah.db.Spend;


public class SpendTableModel extends DefaultTableModel {

	private String[] columnHeaders;
	private ArrayList<Spend> rowData;
	
	public SpendTableModel() {
		columnHeaders = new String[]{"Date", "Member", "Item", "Event", "Pts"};
		rowData = new ArrayList<Spend>();
	}
	
	public SpendTableModel(ArrayList<Spend> rowData) {
		columnHeaders = new String[]{"Date", "Member", "Item", "Event", "Pts"};
		this.rowData = rowData;
	}

	public int getColumnCount() {
		return columnHeaders.length;
	}

	public String getColumnName(int column) {
		return columnHeaders[column];
	}

	public int getRowCount() {
		if (rowData != null)
		{
			return rowData.size();
		}
		else
		{
			return 0;
		}
	}

	public Object getValueAt(int row, int column) {
		Spend spend = rowData.get(row);
		switch (column) {
			case 0:
				return spend.getDate();
			case 1:
				return spend.getMember();
			case 2:
				return spend.getItem();
			case 3:
				return spend.getEvent();
			case 4:
				return spend.getPointsSpent();
		}
		return "";
	}

	public boolean isCellEditable(int row, int column) {
		return false;
	}

	/*
	public void setValueAt(Object value, int row, int column) {
		Spend spend = rowData.get(row);
		switch (column) {
			case 0:
				spend.setMember((Member)value);
			case 1:
				spend.setArrive(TimeUtils.parseTime((String)value));
			case 2:
				spend.setLeave(TimeUtils.parseTime((String)value));
		}
	}*/

	public void updateData(ArrayList<Spend> rowData) {
		this.rowData = rowData;
		fireTableDataChanged();
	}

	public ArrayList<Spend> getSpendList() {
		return rowData;
	}
}
